<template>
  <div>
    <div class="provider-list">
      <div class="content">
        <div class="project-info">
          <div class="form-left-right">
            <el-form
              style="max-width: 1200px"
              :model="form"
              :rules="rules"
              label-position="top"
            >
              <el-form-item label="名称：">
                <el-col>
                  <el-input
                    size="large"
                    v-model="state.form.huiyuanmingcheng"
                  />
                </el-col>
              </el-form-item>
              <el-form-item v-if="state.form.huiyuanleixing == 'gerenhuiyuan'" label="价格：">
                <el-col>
                  <el-input-number size="large" v-model="state.form.jiage" />
                </el-col>
              </el-form-item>
              <el-form-item v-if="state.form.huiyuanleixing == 'gerenhuiyuan'" label="时长：">
                <el-col>
                  <el-input-number size="large" v-model="state.form.shichang" />
                </el-col>
              </el-form-item>
              <el-form-item class="vue-editor" label="权益介绍：">
                <editor
                  :initValue="state.form.quanyijieshao"
                  @onVal="onVal"
                />
              </el-form-item>
              <el-form-item class="button-group">
                <el-button
                  style="margin-left: 100px"
                  type="primary"
                  @click="submitForm"
                  >提交</el-button
                >
                <el-button
                  type="primary"
                  style="margin-left: 50px"
                  @click="$router.go(-1)"
                  >取消</el-button
                >
              </el-form-item>
            </el-form>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
import { reactive } from "vue";
import { useRoute, useRouter } from "vue-router";
import { GetMemberInfo, EditMember } from "@/api/membership";
import { baseMsg } from "@/utils/utils";
const route = useRoute();
const router = useRouter();
const state = reactive({
  form: {
    huiyuanmingcheng: "",
    jiage: "",
    shichang: "",
    // 富文本
    quanyijieshao: "",
  },
});
const GetDetail = () => {
  GetMemberInfo({ id: route.query.id }).then((res) => {
    if (res.code === 4201) {
      state.form = res.data;
    }
  });
};
// 富文本编辑器
const onVal = (val) => {
  state.form.quanyijieshao = val;
};
// 提交表单
const submitForm = () => {
  EditMember(state.form).then((res) => {
    if (res.code == 4202) {
      baseMsg("编辑成功");
      router.go(-1);
    }
  });
};
GetDetail();
</script>
<style lang="scss" scoped>
.content {
  border: none !important;
}
.project-info {
  padding: 30px 100px;
  font-size: 20px;
  color: black;
  display: flex;
}
.el-form-item {
  display: flex;
  align-items: center;
  &.vue-editor {
    align-items: baseline;
  }
}
</style>
<style lang="scss">
.form-left-right {
  .el-form-item .el-form-item__label {
    min-width: 95px;
    margin-bottom: 0 !important;
  }
}
.button-group {
  .el-form-item__content {
    width: 100% !important;
    justify-content: center;
  }
}
</style>
